package com.mf.config;

import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * ClassName: JacksonConfig
 * Package: com.mf.config
 * Description:
 *
 * @Author: lmf
 * @Create: 2024/4/24 9:59
 * @Version: 1.0
 */
@Configuration
public class JacksonConfig {
    @Bean
    public LocalDateTimeSerializer serializer() {
        return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> builder.serializerByType(LocalDateTime.class, serializer());
    }
}
